package com.atguigu.gmall.all.controller;

import com.atguigu.gmall.cart.client.CartFeignClient;
import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.common.utils.AuthContextHolder;
import com.atguigu.gmall.model.cart.CartInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.Enumeration;
import java.util.List;

@Controller
public class CartController {


    @Autowired
    private CartFeignClient cartFeignClient;

    @Autowired

    public static final String REDIRECT = "redirect:";

    @GetMapping("/addCart.html")
    public String addCart(Long skuId, Integer skuNum){
         cartFeignClient.addCart(skuId, skuNum);
         return REDIRECT+"http://cart.gmall.com/addToCart?skuId="+skuId+"&skuNum="+skuNum;
    }
    @GetMapping("/addToCart")
    public String addToCart(Long skuId,Integer skuNum,HttpServletRequest request){
        String userTempId = AuthContextHolder.getUserTempId(request);
        System.out.println(userTempId);
        CartInfo cartInfo = cartFeignClient.addToCart(skuId);
        cartInfo.setSkuNum(skuNum);
        request.setAttribute("cartInfo",cartInfo);
        return "cart/addCart";
    }

    //结算购物车
    @GetMapping("/cart.html")
    public String SettlementCart(Model model){

        return "cart/index";
    }



}
